<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/aui.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="js/init.js"></script>
    <title>修改密码</title>
</head>
<body>
<header>
    <a href="javascript:history.back(-1)" class="f1 head-back"></a>
    <div class="f8">密保信息</div>
    <div class="f1"></div>
</header>
<section class="bg-gray">
    <ul class="pad-3 color-gray">
        <li class="pad-b-3">
            <b class="pad-1-2">修改类型</b>
            <div id="pwdtype" class="flex mar-t-2 pad-l-3">
                <p class="flex" data-type="1">
                    <i class="radio active"></i>
                    <span class="pad-l-1">登陆密码</span>
                </p>
                <p class="flex mar-l-5" data-type="2">
                    <i class="radio"></i>
                    <span class="pad-l-1">二级密码</span>
                </p>
            </div>
        </li>
        <li class="pad-b-3">
            <b class="pad-1-2">原密码</b>
            <div class=" mar-t-2">
                <input id="oldpassword" class="col-10 pad-1-2 bg-white border-radius-1 border-gray" type="password" placeholder="请输入原密码">
            </div>
        </li>
        <li class="pad-b-3">
            <b class="pad-1-2">新密码</b>
            <div class=" mar-t-2">
                <input id="newpassword" class="col-10 pad-1-2 bg-white border-radius-1 border-gray" type="password" placeholder="请输入新密码">
            </div>
        </li>
        <li class="pad-b-3">
            <b class="pad-1-2">确认密码</b>
            <div class=" mar-t-2">
                <input id="newpassword2" class="col-10 pad-1-2 bg-white border-radius-1 border-gray" type="password" placeholder="请确认新密码">
            </div>
        </li>
        <li class="col-3 bg-blue border-radius-1 color-white center line-h-2 mar-l-5" onclick="modify()">修改</li>
    </ul>
</section>
<script src="js/foot.js"></script>
<script>
    var pwdtype = 1;
    $("#pwdtype p").click(function () {
        $("#pwdtype p .radio").removeClass('active');
        $(this).children('.radio').addClass('active');
        pwdtype = $(this).attr('data-type');

    });

    // 修改事件
    function modify() {
        var oldpwd = $("#oldpassword").val();
        var newpwd = $("#newpassword").val();
        var newpwd2 = $("#newpassword2").val();
        if(!oldpwd || !newpwd){
            toast('请填写完整信息');
            return;
        }
        if(newpwd != newpwd2){
            toast('二次输入密码不一致');
            return;
        }
        var data = {};
        data.userid = localStorage.user_id;
        data.token = localStorage.token;
        if(pwdtype == 1){
            data.oldpassword = oldpwd;
            data.newpassword = newpwd;
            Request('index/Mycenter/passwd');
        }
        if(pwdtype == 2){
            data.oldpassword_2 = oldpwd;
            data.newpassword_2 = newpwd;
            Request('index/Mycenter/passwd_2');
        }

        function Request(url) {
            new AjaxRequest({
                type: 'post',
                dataType: 'json',
                url: hostUrl + url,
                data: data,
                callback: res => {
                    toast(res.msg);
                    if(res.status == 1){
                        setTimeout(function () {
                            location.href = 'my.html';
                        },2000)
                    }
                },
                error: err => {
                    // toast('请求错误');
                    // console.log(err)
                }
            });
        }

    }
</script>

</body>
</html>